package pojo.postman;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@NoArgsConstructor
@Data
public class PostManRequest {

    private String method;
    private List<?> header;
    private BodyDTO body;
    private UrlDTO url;
    private ArrayList response = new ArrayList();

    @Data
    public static class BodyDTO {
        private String mode;
        private String raw;
        private OptionsDTO options;

        @Data
        public static class OptionsDTO {
            private RawDTO raw;

            @Data
            public static class RawDTO {
                private String language;

                public RawDTO(String language) {
                    this.language = language;
                }

                public RawDTO() {
                }

                public String getLanguage() {
                    language = Optional.ofNullable(language).orElse("");
                    return language;
                }

                public void setLanguage(String language) {
                    this.language = language;
                }
            }

            public OptionsDTO(RawDTO raw) {
                this.raw = raw;
            }

            public OptionsDTO() {
            }
        }

        public BodyDTO(String mode, String raw, OptionsDTO options) {
            this.mode = mode;
            this.raw = raw;
            this.options = options;
        }

        public BodyDTO() {
        }

        public String getMode() {
            mode = Optional.ofNullable(mode).orElse("");
            return mode;
        }

        public void setMode(String mode) {
            this.mode = mode;
        }

        public String getRaw() {
            raw = Optional.ofNullable(raw).orElse("");
            return raw;
        }

        public void setRaw(String raw) {
            this.raw = raw;
        }

        public OptionsDTO getOptions() {
            options = Optional.ofNullable(options).orElse(new OptionsDTO());
            return options;
        }

        public void setOptions(OptionsDTO options) {
            this.options = options;
        }
    }

    @Data
    public static class UrlDTO {
        private String raw;
        private List<String> host;
        private String port;
        private List<String> path;

        public UrlDTO(String raw, List<String> host, String port, List<String> path) {
            this.raw = raw;
            this.host = host;
            this.port = port;
            this.path = path;
        }

        public UrlDTO() {
        }

        public String getRaw() {
            raw = Optional.ofNullable(raw).orElse("");
            return raw;
        }

        public void setRaw(String raw) {
            this.raw = raw;
        }

        public List<String> getHost() {
            host = Optional.ofNullable(host).orElse(new ArrayList<>());
            return host;
        }

        public void setHost(List<String> host) {
            this.host = host;
        }

        public String getPort() {
            port = Optional.ofNullable(port).orElse("");
            return port;
        }

        public void setPort(String port) {
            this.port = port;
        }

        public List<String> getPath() {
            path = Optional.ofNullable(path).orElse(new ArrayList<>());
            return path;
        }

        public void setPath(List<String> path) {
            this.path = path;
        }
    }

    public String getMethod() {
        method = Optional.ofNullable(method).orElse("");
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public List<?> getHeader() {
        header = Optional.ofNullable(header).orElse(new ArrayList<>());
        return header;
    }

    public void setHeader(List<?> header) {
        this.header = header;
    }

    public BodyDTO getBody() {
        body = Optional.ofNullable(body).orElse(new BodyDTO());
        return body;
    }

    public void setBody(BodyDTO body) {
        this.body = body;
    }

    public UrlDTO getUrl() {
        url = Optional.ofNullable(url).orElse(new UrlDTO());
        return url;
    }

    public void setUrl(UrlDTO url) {
        this.url = url;
    }

    public ArrayList getResponse() {
        response = Optional.ofNullable(response).orElse(new ArrayList<>());
        return response;
    }

    public void setResponse(ArrayList response) {
        this.response = response;
    }
}
